export default {
  inserted(el) {
    el.style.position = 'fixed';
    el.style.cursor = 'move';
    el.style.userSelect = 'none'; // 禁用文本选择

    let startX = 0, startY = 0;
    let initialX = 0, initialY = 0;

    const mousedown = (e) => {
      startX = e.clientX;
      startY = e.clientY;
      document.addEventListener('mousemove', mousemove);
      document.addEventListener('mouseup', mouseup);
    };

    const mousemove = (e) => {
      const dx = e.clientX - startX;
      const dy = e.clientY - startY;
      el.style.transform = `translate(${initialX + dx}px, ${initialY + dy}px)`;
    };

    const mouseup = (e) => {
      initialX += e.clientX - startX;
      initialY += e.clientY - startY;
      document.removeEventListener('mousemove', mousemove);
      document.removeEventListener('mouseup', mouseup);
    };

    el.addEventListener('mousedown', mousedown);
  }
};